package org.medusa.db.handlersocket;

import java.util.HashMap;
import java.util.Map;

/**
 * Row definition
 */
public class HandlerSocketRow {

	public static final String TMTab = "";
	public static final String Tab = "";
	public static final String TMReturn = "";
	public static final String Return = "";
	
	private Map<String, String> data= new HashMap<String, String>();;

	public HandlerSocketRow() {
	}

	public HandlerSocketRow(Map<String, String> data) {
		this.data = data;
		if (this.data == null)
			this.data = new HashMap<String, String>();
	}

	public boolean NotNull() {
		return (this.data.size() > 0);
	}

	public boolean IsNull() {
		return (this.data.size() == 0);
	}
	/*
	private String get_field_value(String field) {
		if(this.data.containsKey(field))
			return this.data.get(field);
		return "";
	}*/
	public boolean GetField_Bool(String field) {
		return (Integer.parseInt(this.data.get(field)) != 0);
	}

	public int GetField_Int(String field) {
		return Integer.parseInt(this.data.get(field));
	}

	// int8
	public byte GetField_Int8(String field) {
		return Byte.parseByte(this.data.get(field));
	}

	// int16
	public short GetField_Int16(String field) {
		return Short.parseShort(this.data.get(field));
	}

	// int64
	public long GetField_Int64(String field) {
		return Long.parseLong(this.data.get(field));
	}

	// float32
	public float GetField_Float32(String field) {
		return Float.parseFloat(this.data.get(field));
	}

	// float64
	public double GetField_Float64(String field) {
		return Double.parseDouble(this.data.get(field));
	}

	public String GetField_String(String field) {
		String ff = this.data.get(field).trim();
		ff=ff.replace(TMTab, Tab);
		ff=ff.replace(TMReturn, Return);
		return ff;
	}
	
	public String GetField(String field) {
		return this.GetField_String(field);
	}
}